<template>
	<view class="bg-content">
		<view class="content">
			<view class="user-name">
				<span>昵称 </span> : {{userinfo.username}}
			</view>

			<view class="dkjbl">
				抵扣金抵扣比例: {{value}}%
			</view>

			<view class="qrcode">
				<u-image :src="qrcodeUrl" width="100%" height="100%"></u-image>
			</view>

			<view class="handle-box">
				<view class="save-img" @click="saves">
					保存二维码
				</view>
				<view class="setting-btn" @click="show=true">
					设置
				</view>
			</view>

			<view class="skmx" @click="handleRoute">
				<view class="s-left">
					收款明细
				</view>
				<view class="s-right">
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
		</view>
		<u-modal v-model="show" show-cancel-button title="请输入抵扣金比例 %" @confirm="handleConfirm">
			<view class="slot-content">
				<u-input v-model="value" type="number" border placeholder="请输入" trim />
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userinfo: {},
				bl: 5,
				show: false,
				value: 0,
				qrcodeUrl: ''
			}
		},
		onShow() {
			this.massage()
			this.getDeduct()
			
			
		},
		methods: {
			getDeduct(){
				this.$api.getDeduct({}, res => {
					console.log(res)
					this.value = res.data.data.deduct
					this.getQrcode()
				})
			},
			massage() {
				this.$api.get_my_massage({}, res => {
					if (res.data.code == 1) {
						this.userinfo = res.data.data.data
					}
					this.$api.getUserData({
						id: this.userinfo.id
					}, res => {
						console.log(res)
					})
				})
			},
			getQrcode() {
				this.$api.getQrcodeImg({
					count: this.value
				}, res => {
					this.qrcodeUrl = res.data.data

				})
			},
			handleRoute() {
				this.$u.route('/subcontract/paymentlog/paymentlog')
			},
			saves() {
				uni.getImageInfo({
					src: this.qrcodeUrl,
					success: (res) => {
						const path = res.path;
						console.log(res)
						uni.saveImageToPhotosAlbum({
							filePath: path,
							success: function() {
								uni.showToast({
									icon: 'none',
									title: '保存成功'
								})
								console.log('save success');
							},
							fail: (err) => {
								console.log(err)
							}
						});
					},
					fail: (res) => {
						console.log(res)
					}
				})
			},
			handleConfirm() {
				if (!this.value) {
					uni.showToast({
						icon: 'none',
						title: '请输入抵扣金抵扣比例'
					})
					this.show = true
					return
				}
				if(this.value>99){
					uni.showToast({
						icon: 'none',
						title: '请输入0～99之内的数字'
					})
					this.show = true
					return
				}
				this.getQrcode()
			}
		}
	}
</script>

<style>
	.bg-content {
		width: 100vw;
		height: 100vh;
		background-color: #f29100;
		overflow: hidden;

	}

	.content {
		background-color: #fff;
		margin: 10rpx 20rpx;
		min-height: 400rpx;
		border-radius: 15rpx;
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		align-items: center;
	}

	.user-name {
		font-weight: bold;
		padding-top: 30rpx;
	}

	.dkjbl {
		font-size: 18rpx;
		color: red;
		padding-top: 30rpx;
	}

	.qrcode {
		/* background-color: red; */
		width: 400rpx;
		height: 400rpx;
		margin-top: 20rpx;
	}

	.handle-box {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 30rpx 90rpx;
	}

	.save-img {
		padding-left: 20rpx;
	}

	.save-img,
	.setting-btn {
		flex: 1;
		text-align: center;
		font-size: 28rpx;
	}

	.skmx {
		width: 90%;
		margin: 20rpx 0rpx;
		padding: 30rpx 0rpx;
		border-top: 1rpx solid #eee;
		display: flex;
		justify-content: space-between;
	}

	.slot-content {
		margin: 30rpx;
	}
</style>